package com.myown.listenner;

import com.myown.constant.ConstantInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * 路径初始化监听器 <p>
 * @author lincky
 * @version v1.0.0
 */
public class PathConfigListenner implements ServletContextListener{

    // 日志记录对象
    private final static Logger logger = LoggerFactory.getLogger(PathConfigListenner.class);

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        /*
            获取服务器物理路径
         */
        String absolutePath = sce.getServletContext().getRealPath("/");
        ConstantInfo.pathInit(absolutePath.substring(0, absolutePath.length() -1));
        logger.debug("project absolute path = {}", ConstantInfo.Path.ABSOLUTE_ROOT);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}
